package com.hdu.webServer.write;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

@Slf4j
public class WriteClient {

    public static void main(String[] args) throws IOException {
        SocketChannel clientSocket = SocketChannel.open();
        clientSocket.connect(new InetSocketAddress("localhost", 8080));
        int count = 0;
        ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024);
        do {
            int read = clientSocket.read(buffer);
            count += read;
            log.info("本次读到的数据长度 : {}", read);
            buffer.clear();
        } while (count != 3000000);

        log.info("总共读到的数据长度 : {}", count);
    }
}
